package com.qzf.test.test;

import com.qzf.test.model.Brand;
import com.qzf.test.model.Cell;
import com.qzf.test.model.Layer;
import com.qzf.test.model.Map;
import com.qzf.test.utils.MapUtils;
import com.qzf.test.utils.PlayerUtils;
import javax.swing.*;
import java.util.List;

public class TestReaderMap extends JFrame{


    public static void main(String[] args) {
        new TestReaderMap();
    }


    public static Map m=MapUtils.builderMap(6);
    public TestReaderMap(){
        this.setTitle("大数据01-羊了羊");
        this.setSize(450,800);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
        this.setLocationRelativeTo(null);
        this.setVisible(true);

        this.setBounds(0,0,450,800);
        List<Layer> list =m.getList();

        for (int i=0;i<list.size();i++){
            Layer layer =list.get(i);
            showInfo(layer);
        }
        m.compareALL();
        autoFlush();

        PlayerUtils.getInstance().play();
    }



    public void showInfo(Layer layer){
        Cell[][] cells =layer.getCells();
        for (int row=0;row<cells.length;row++){
            for(int col=0;col<cells[row].length;col++){
                Brand brand =cells[row][col].getBrand();
                int x=col*50+layer.getOffsetx();
                int y=row*50+layer.getOffsety();
                brand.setBounds(x,y,50,50);
                this.getContentPane().add(brand);
            }
        }
    }
    public void autoFlush() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    repaint();
                    try {
                        Thread.sleep(40);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();

    }
}
